home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 033a / sendcom_.zip / SENDCOM.CPP < prev    next >
C/C++ Source or Header  |  1991-10-14  |  3KB  |  143 lines

  1. #include <iostream.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <sys\stat.h>
  5. #include <fcntl.h>
  6. #include <ctype.h>
  7. #include <dos.h>
  8. #include <string.h>
  9. #include "pcbsys.h"
  10.  
  11. #define CR "\n\r"
  12. #define rs232 0x14
  13. #define writech 1
  14. #define mask 0x7f
  15.  
  16. #define YES 1
  17. #define NO  0
  18.  
  19. #define DATA_READY 0
  20. #define OVERRUN 0x1
  21. #define PARITY 0x2
  22. #define FRAMING 0x8
  23. #define BRK 0x10
  24. #define HOLDEMPTY 0x20
  25. #define SHIFTEMPTY 0x40
  26. #define FAILED 0x80
  27.  
  28. union REGS regs;
  29.  
  30. int LOCAL;
  31. int COMPORT,mode,fileflag;
  32. char commandline[255];
  33. char filter[80];
  34.  
  35. extern int ANSI;
  36. char *pcb_printf(char *);
  37.  
  38. void xmit(char);
  39. void sendstr(char *);
  40. void CRLF(int);
  41.  
  42. /*::::::::::::::::::::::::[ DISPLAY SECURITY FILE ]::::::::::::::::::::*/
  43. void display_file(char *filename){
  44.         FILE *fp;
  45.         char buffer[85];
  46.         int bufflen=80;
  47.         if((fp=fopen(filename,"r"))==NULL){
  48.             strcpy(commandline,filename);
  49.             strcat(commandline," was not found!");
  50.             sendstr(commandline);
  51.             exit(1);}
  52.         CRLF(1);
  53.         while((fgets(buffer,bufflen,fp))!=NULL){
  54.             if(!strcmp(filter,"")){
  55.                 sendstr(buffer);
  56.                 xmit('\r');}
  57.             else
  58.                 if(strstr(buffer,filter)){
  59.                     sendstr(buffer);
  60.                     xmit('\r');}
  61.         }
  62.         fclose(fp); }
  63.  
  64. /*:::::::::::::::::::::::[ Send CR LF ]:::::::::::::::::::::::::::*/
  65. void CRLF(int cnt){
  66.         int i;
  67.         for (i=0;i<cnt;i++){
  68.             xmit('\n');
  69.             xmit('\r');
  70.             printf("\n");    }}
  71.  
  72. /*::::::::::::::[ SEND ONE CHARACTER TO SERIAL PORT ]::::::::::::::*/
  73. void xmit(char ch){
  74.         int flag;
  75.         if(LOCAL==YES) return;
  76.         regs.h.ah = writech;
  77.         regs.x.dx = COMPORT;
  78.         regs.h.al = ch;
  79.         int86(rs232,®s,®s);
  80.         flag =(regs.h.ah&FAILED);
  81.         if (flag!=0){
  82.             printf("  COM%d failed!  ",COMPORT+1);
  83.             exit(1);}
  84. }
  85.  
  86. /*::::::::::::::::::[ Send string to Com ]:::::::::::::::::::::::*/
  87. void xmit_str(char *s){
  88.         while(*s != '\0'){
  89.                 xmit(*s);
  90.                 s++;        }}
  91.  
  92.  
  93. /*:::::::::::::::::::[ Send string to COM or CON ]::::::::::::::::::*/
  94. void sendstr(char *s){
  95.         char *str;
  96.         str=pcb_printf(s);
  97.         xmit_str(str);
  98. }
  99.  
  100. /*:::::::::::::::::::[ Get command line ]:::::::::::::::::::::::::::*/
  101. void getcline(int cnt,char *argarray[]){
  102.         int i;
  103.         memset(commandline,'\0',255);
  104.         for(i=1;i<cnt;i++){
  105.                 if(!strcmp(strupr(argarray[i]),"/F")){
  106.                     fileflag=1;
  107.                     strcpy(commandline,argarray[i+1]);
  108.                     if(cnt>4) strcpy(filter,argarray[i+2]);
  109.                     else strcpy(filter,"");
  110.                     return;                }
  111.                 if(!strcmp(argarray[i],"CR"))
  112.                     strcat(commandline,CR);
  113.                 else {
  114.                     strcat(commandline,argarray[i]);
  115.                     strcat(commandline," ");        }}}
  116.  
  117. main(int argc,char *argv[]){
  118.         mode=0;
  119.  
  120.         if((pcbs.getdata(pcbs))==-1){
  121.             cout << "\nCouldn't read PCBOARD.SYS\n\n";
  122.             exit(1);
  123.         }
  124.  
  125.         char gm=pcbs.get_graphics();
  126.         switch (gm){
  127.             case 'Y':ANSI=YES;break;
  128.             case 'N':
  129.             case '7':ANSI=NO;break;
  130.         }
  131.  
  132.         if((strcmp(pcbs.get_connectspeed(),"Local"))==0)
  133.             LOCAL=YES;
  134.         else LOCAL=NO;
  135.  
  136.         COMPORT=pcbs.get_comport()-'1';
  137.         getcline(argc,argv);
  138.         if (fileflag==1)
  139.             display_file(commandline);
  140.         else
  141.             sendstr(commandline);
  142. }
  143.